#include<iostream>
using namespace std;

struct ListNode {
  int val;
  ListNode *next;
  ListNode() : val(0), next(NULL) {}
  ListNode(int x) : val(x), next(NULL) {}
  ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        ListNode* l3 = new ListNode(0);
        ListNode* res= l3;
        
        int carry = 0;
        
		while(l1 || l2 || carry){
        	
        	int sum = carry;
        	
        	if(l1){
        		sum += l1->val;
        		l1 = l1->next;
			}
			
			if(l2){
        		sum += l2->val;
        		l2 = l2->next;
			}
			carry = sum / 10;
			l3->val = sum % 10;
			if(l1 || l2 || carry){
				l3->next = new ListNode(0);
				l3 = l3->next;
			}
		}
		return res;  
    }
};

int main(){
	Solution s;
	
	
	return 0;
} 
